$.namespace("net.htwater.GoogleMap");
net.htwater.GoogleMap = {
	myLatlng : new google.maps.LatLng(29.875, 121.556830), // 宁波的经纬度
	initialize : function() {
		var myOptions = {
			center : net.htwater.GoogleMap.myLatlng,
			zoom : 4,
			mapTypeId : google.maps.MapTypeId.TERRAIN, //google.maps.MapTypeId.SATELLITE,
			mapTypeControlOptions : {
				// mapTypeIds : [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN],
				mapTypeIds : [],
				position : google.maps.ControlPosition.LEFT_BOTTOM
			},
			styles : [ {
				//elementType : "all",
				featureType : "road",
				stylers : [ {
					visibility : "off"
				} ]
			},  {
				//elementType : "all",
				featureType : "transit",
				stylers : [ {
					visibility : "off"
				} ]
			}
			/*, {
				elementType : "all",
				stylers : [ {
					visibility : "on"
				} ]
			}*/ ],
			streetViewControl : false,
			zoomControl : true,
			zoomControlOptions : {
				style : google.maps.ZoomControlStyle.SMALL,
				position : google.maps.ControlPosition.RIGHT_CENTER
			},
			navigationControl : false
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	},
	pan2Ningbo : function() {
		map.panTo(net.htwater.GoogleMap.myLatlng);
		map.setZoom(5);
	},
	loadKML : function(kmlUrl, preserveViewport) {
		if (null == preserveViewport) {
			preserveViewport = false;
		}
		var kmlLayer = new google.maps.KmlLayer(kmlUrl, {
			clickable : true,
			map : map,
			preserveViewport : preserveViewport
		});
		kmlLayer.setMap(map);
		return kmlLayer;
	},
	addWeatherLayer : function() {
		var weatherLayer = new google.maps.weather.WeatherLayer({
			temperatureUnits : google.maps.weather.TemperatureUnit.CELCIUS
		});
		weatherLayer.setMap(map);
	},
	addCloudLayer : function() {
		// set weather layer
		var cloudLayer = new google.maps.weather.CloudLayer();
		cloudLayer.setMap(map);
		return cloudLayer;
	},
	addWarningLine : function() {
		// set warning line
		var wline24 = [new google.maps.LatLng(34.266667, 126.80888), new google.maps.LatLng(22.2, 126.80888), new google.maps.LatLng(14.75, 110.16666)];
		var wline24Path = new google.maps.Polyline({
			path : wline24,
			strokeColor : "#FFE426",
			strokeOpacity : 1.0,
			strokeWeight : 2
		});
		wline24Path.setMap(map);
		var wline48 = [new google.maps.LatLng(34.266667, 132.0), new google.maps.LatLng(22.2, 132.0), new google.maps.LatLng(14.75, 124.0), new google.maps.LatLng(14.75, 108.3)];
		var wline48Path = new google.maps.Polyline({
			path : wline48,
			strokeColor : "#456ED7",
			strokeOpacity : 1.0,
			strokeWeight : 2
		});
		wline48Path.setMap(map);

		var wBounds24 = new google.maps.LatLngBounds(new google.maps.LatLng(26.2, 126.2), new google.maps.LatLng(29.4, 126.80));
		var w24 = new google.maps.GroundOverlay("images/warning24.png", wBounds24, {
			clickable : false
		});
		w24.setMap(map);
		var wBounds48 = new google.maps.LatLngBounds(new google.maps.LatLng(26.2, 131.4), new google.maps.LatLng(29.4, 132.0));
		var w48 = new google.maps.GroundOverlay("images/warning48.png", wBounds48, {
			clickable : false
		});
		w48.setMap(map);
	},
	addPolyLine : function(locations) {
		var polyline = new google.maps.Polyline({
			path : locations,
			strokeColor : "gray",
			strokeOpacity : 1.0,
			strokeWeight : 2
		});
		polyline.setMap(map);
		return polyline;
	},
	cleanPolyLine : function(polyline) {
		polyline.setMap(null);
	},
	drawCircle : function(location, radius, color) {
		var circle = new google.maps.Circle({
			center : location,
			fillColor : color,
			fillOpacity : 0.3,
			radius : radius,
			strokeColor : "black",
			strokeWeight : 0.1
		});
		circle.setMap(map);
		return circle;
	},
	addDot : function(image, infowindow, location, title, contentString, markersArray) {
		var marker = new google.maps.Marker({
			position : location,
			map : map,
			title : title,
			icon : image
		});
		markersArray.push(marker);
		// set bubble layer
		contentString = '<h2>' + title + '</h2>' + '<p>' + contentString;
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(contentString);
			infowindow.open(map, marker);
			map.panTo(marker.getPosition());
			map.setZoom(5);
		});
	},
	addDot : function(image, infowindow, location, title, contentString, markersArray, zoom) {
		var marker = new google.maps.Marker({
			position : location,
			map : map,
			title : title,
			icon : image
		});
		markersArray.push(marker);
		// set bubble layer
		contentString = '<h2>' + title + '</h2>' + '<p>' + contentString;
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(contentString);
			infowindow.open(map, marker);
			map.panTo(marker.getPosition());
			map.setZoom(zoom);
		});
	},
	addMarkerWithColor : function(infowindow, location, title, contentString, markersArray, image, color) {
		if(null == image) {
			image = 'images/pin_blue.png';
		}
		if (null == color) {
			color = '#ffffff';
		}
		var marker = new google.maps.Marker({
			position : location,
			map : map,
			title : title.split('@')[0],
			icon : image
		});
		var mapLabel = new MapLabel({
			text : title,
			position : location,
			map : map,
			fontSize : 12,
			align : 'center'
		});
		mapLabel.set('strokeColor', color);
		mapLabel.set('position', location);
		marker.bindTo('map', mapLabel);
		marker.bindTo('position', mapLabel);
		markersArray.push(marker);
		// set bubble layer
		contentString = '<h2>' + title.split('@')[0] + '</h2>' + '<p>' + contentString;
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(contentString);
			infowindow.open(map, marker);
			map.panTo(marker.getPosition());
			//map.setZoom(11);
		});
	},
	addMarker : function(infowindow, location, title, contentString, markersArray, image) {
		if(null == image) {
			image = 'images/pin_blue.png';
		}
		var marker = new google.maps.Marker({
			position : location,
			map : map,
			title : title.split('@')[0],
			icon : image
		});
		var mapLabel = new MapLabel({
			text : title,
			position : location,
			map : map,
			fontSize : 12,
			align : 'center'
		});
		mapLabel.set('position', location);
		marker.bindTo('map', mapLabel);
		marker.bindTo('position', mapLabel);
		markersArray.push(marker);
		// set bubble layer
		contentString = '<h2>' + title.split('@')[0] + '</h2>' + '<p>' + contentString;
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(contentString);
			infowindow.open(map, marker);
			map.panTo(marker.getPosition());
			map.setZoom(11);
		});
	},
	// Removes the overlays from the map, but keeps them in the array
	clearOverlays : function(markersArray) {
		if(markersArray) {
			for(i in markersArray) {
				markersArray[i].setMap(null);
			}
			markersArray = [];
		}
	},
	// Shows any overlays currently in the array
	showOverlays : function(markersArray) {
		if(markersArray) {
			for(i in markersArray) {
				markersArray[i].setMap(map);
			}
		}
	},
	// Deletes all markers in the array by removing references to them
	deleteOverlays : function(markersArray) {
		if(markersArray) {
			for(i in markersArray) {
				markersArray[i].setMap(null);
			}
			markersArray.length = 0;
		}
	}
}